package com.fance.highlight_spring4.ch3.taskscheduler;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author fance
 * @date 18-5-6 上午10:45
 */
@Service
public class ScheduledTaskService {

    public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm:ss");

    @Scheduled(fixedRate = 5000)
    public void reportCurrentTime() {

        System.out.println("每隔5秒执行一次 " + DATE_FORMAT.format(new Date()));
    }


    @Scheduled(cron = "0 51 10 ? * *")
    public void fixTimeExecution() {
        System.out.println("指定时间 " + DATE_FORMAT.format(new Date()) + "执行");

    }

}
